package com.jh.hts_jdk.utils;

import java.io.File;
import java.util.HashMap;
import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * Constant
 */
public class Constant {

    public static final String Version = "1.2";
    public static final String Author = "JiangHao";
    public static final String Email = "john-jh@foxmail.com";
    public static final File JarFile = new File(Constant.class.getProtectionDomain().getCodeSource().getLocation().getFile());
    public static final Character[] BASE_ALPHABET = new Character[]{'A','C','G','T'};
    public static final Character[] AMINO_ALPHABET = new Character[]{'A', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'V', 'W', 'Y', '*'};
    public static final Character[] BASE_ALPHABET_EXTEND = new Character[]{'A','C','G','T','N','-'};
    public static final HashMap<Character, Character> BASE_ALPHABET_COMPLETE = new HashMap<>(){{
        put('A', 'T');
        put('T', 'A');
        put('C', 'G');
        put('G', 'C');
        put('R', 'Y');
        put('Y', 'R');
        put('S', 'S');
        put('W', 'W');
        put('K', 'M');
        put('M', 'K');
        put('B', 'V');
        put('V', 'B');
        put('D', 'H');
        put('H', 'D');
        put('N', 'N');
        put('-', '-');
    }};
    
    public static final String[] CODON_LIST = {
        "AAA", "AAC", "AAG", "AAT", "ACA", "ACC", "ACG", "ACT", 
        "AGA", "AGC", "AGG", "AGT", "ATA", "ATC", "ATG", "ATT", 
        "CAA", "CAC", "CAG", "CAT", "CCA", "CCC", "CCG", "CCT",
        "CGA", "CGC", "CGG", "CGT", "CTA", "CTC", "CTG", "CTT", 
        "GAA", "GAC", "GAG", "GAT", "GCA", "GCC", "GCG", "GCT", 
        "GGA", "GGC", "GGG", "GGT", "GTA", "GTC", "GTG", "GTT", 
        "TAA", "TAC", "TAG", "TAT", "TCA", "TCC", "TCG", "TCT", 
        "TGA", "TGC", "TGG", "TGT", "TTA", "TTC", "TTG", "TTT"};
    public static final HashMap<Character, String> AMBIGUOUS_BASE_TABLE = new HashMap<>(){{
        put('A', "A");
        put('C', "C");
        put('G', "G");
        put('T', "T");
        put('R', "AG");
        put('Y', "CT");
        put('S', "GC");
        put('W', "AT");
        put('K', "GT");
        put('M', "AC");
        put('B', "CGT");
        put('D', "AGT");
        put('H', "ACT");
        put('V', "ACG");
        put('N', "ACGT");
    }};
    public static final HashMap<String, Character> CODON_TABLE = new HashMap<>(){{
        put("TTT", 'F');
        put("TTC", 'F');
        put("TTA", 'L');
        put("TTG", 'L');
        put("CTT", 'L');
        put("CTC", 'L');
        put("CTA", 'L');
        put("CTG", 'L');
        put("ATT", 'I');
        put("ATC", 'I');
        put("ATA", 'I');
        put("ATG", 'M');
        put("GTT", 'V');
        put("GTC", 'V');
        put("GTA", 'V');
        put("GTG", 'V');
        put("TCT", 'S');
        put("TCC", 'S');
        put("TCA", 'S');
        put("TCG", 'S');
        put("CCT", 'P');
        put("CCC", 'P');
        put("CCA", 'P');
        put("CCG", 'P');
        put("ACT", 'T');
        put("ACC", 'T');
        put("ACA", 'T');
        put("ACG", 'T');
        put("GCT", 'A');
        put("GCC", 'A');
        put("GCA", 'A');
        put("GCG", 'A');
        put("TAT", 'Y');
        put("TAC", 'Y');
        put("TAA", '*'); // 终止密码子
        put("TAG", '*'); // 终止密码子
        put("CAT", 'H');
        put("CAC", 'H');
        put("CAA", 'Q');
        put("CAG", 'Q');
        put("AAT", 'N');
        put("AAC", 'N');
        put("AAA", 'K');
        put("AAG", 'K');
        put("GAT", 'D');
        put("GAC", 'D');
        put("GAA", 'E');
        put("GAG", 'E');
        put("TGT", 'C');
        put("TGC", 'C');
        put("TGA", '*'); // 终止密码子
        put("TGG", 'W');
        put("CGT", 'R');
        put("CGC", 'R');
        put("CGA", 'R');
        put("CGG", 'R');
        put("AGT", 'S');
        put("AGC", 'S');
        put("AGA", 'R');
        put("AGG", 'R');
        put("GGT", 'G');
        put("GGC", 'G');
        put("GGA", 'G');
        put("GGG", 'G');
    }};

    public static RejectedExecutionHandler rejectionHandler = new RejectedExecutionHandler() {
        @Override
        public void rejectedExecution(Runnable runnable, ThreadPoolExecutor executor) {
            try {
                executor.getQueue().put(runnable);//将任务加到队列中，put方法可以在队列已满的情况下等待
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    };
}
